package com.mib.browser;

import javax.swing.*;
import java.io.*;
import java.util.Properties;

public class MIBBrowserSettings implements Serializable {
    private Properties prop = new Properties();
    private static final String SETTINGS_FILE_NAME = ".mib-browser";
    private int vericalDividerLocation = 200;
    private int horizontalDividerLocation = 200;
    private int frameWidth = 600;
    private int frameHeight = 600;
    private int frameX = 20;
    private int frameY = 20;
    private String[] ips = new String[5];
    private String[] oids = new String[5];

    public MIBBrowserSettings() {
        int i;
        for(i = 0; i < this.ips.length; ++i) {
            this.ips[i] = new String("");
        }

        for(i = 0; i < this.oids.length; ++i) {
            this.oids[i] = new String("");
        }

    }

    public void load() {
        try {
            File file = new File(".mib-browser");
            if (!file.exists()) {
                file.createNewFile();
                return;
            }

            this.prop.load(new FileInputStream(".mib-browser"));
            this.setFrameWidth(new Integer(this.prop.getProperty("FrameWidth")));
            this.setFrameHeight(new Integer(this.prop.getProperty("FrameHeight")));
            this.setFrameX(new Integer(this.prop.getProperty("FrameX")));
            this.setFrameY(new Integer(this.prop.getProperty("FrameY")));
            this.setVericalDividerLocation(new Integer(this.prop.getProperty("VericalDividerLocation")));
            this.setHorizontalDividerLocation(new Integer(this.prop.getProperty("HorizontalDividerLocation")));
            this.ips[0] = this.prop.getProperty("IP0");
            this.ips[1] = this.prop.getProperty("IP1");
            this.ips[2] = this.prop.getProperty("IP2");
            this.ips[3] = this.prop.getProperty("IP3");
            this.ips[4] = this.prop.getProperty("IP4");
            this.oids[0] = this.prop.getProperty("OID0");
            this.oids[1] = this.prop.getProperty("OID1");
            this.oids[2] = this.prop.getProperty("OID2");
            this.oids[3] = this.prop.getProperty("OID3");
            this.oids[4] = this.prop.getProperty("OID4");
        } catch (IOException var2) {
            var2.printStackTrace();
        }

    }

    public void save() {
        try {
            this.prop.setProperty("FrameWidth", (new Integer(this.getFrameWidth())).toString());
            this.prop.setProperty("FrameHeight", (new Integer(this.getFrameHeight())).toString());
            this.prop.setProperty("FrameX", (new Integer(this.getFrameX())).toString());
            this.prop.setProperty("FrameY", (new Integer(this.getFrameY())).toString());
            this.prop.setProperty("VericalDividerLocation", (new Integer(this.getVericalDividerLocation())).toString());
            this.prop.setProperty("HorizontalDividerLocation", (new Integer(this.getHorizontalDividerLocation())).toString());
            this.prop.setProperty("IP0", this.ips[0]);
            this.prop.setProperty("IP1", this.ips[1]);
            this.prop.setProperty("IP2", this.ips[2]);
            this.prop.setProperty("IP3", this.ips[3]);
            this.prop.setProperty("IP4", this.ips[4]);
            if (this.oids[0] == null) {
                System.out.println("oids[0] null");
            }

            if (this.oids[1] == null) {
                System.out.println("oids[1] null");
            }

            this.prop.setProperty("OID0", this.oids[0]);
            this.prop.setProperty("OID1", this.oids[1]);
            this.prop.setProperty("OID2", this.oids[2]);
            this.prop.setProperty("OID3", this.oids[3]);
            this.prop.setProperty("OID4", this.oids[4]);
            this.prop.store(new FileOutputStream(".mib-browser"), null);
        } catch (Exception var2) {
            var2.printStackTrace();
        }

    }

    public void setIPs(DefaultComboBoxModel model) {
        int counter = 0;

        int i;
        for(i = model.getSize() - 1; i >= 0 && counter != 5; --i) {
            if (model.getElementAt(i) != null) {
                this.ips[counter] = (String)model.getElementAt(i);
                ++counter;
            }
        }

        if (counter < 5) {
            for(i = counter; i < 5; ++i) {
                this.ips[counter] = new String("");
            }
        }

    }

    public void setOIDs(DefaultComboBoxModel model) {
        int counter = 0;

        int i;
        for(i = model.getSize() - 1; i >= 0 && counter != 5; --i) {
            if (model.getElementAt(i) != null) {
                this.oids[counter] = (String)model.getElementAt(i);
                ++counter;
            }
        }

        if (counter < 5) {
            for(i = counter; i < 5; ++i) {
                this.oids[counter] = new String("");
            }
        }

    }

    public String[] getIPs() {
        return this.ips;
    }

    public String[] getOIDs() {
        return this.oids;
    }

    public int getVericalDividerLocation() {
        return this.vericalDividerLocation;
    }

    public void setVericalDividerLocation(int vericalDividerLocation) {
        this.vericalDividerLocation = vericalDividerLocation;
    }

    public int getHorizontalDividerLocation() {
        return this.horizontalDividerLocation;
    }

    public void setHorizontalDividerLocation(int horizontalDividerLocation) {
        this.horizontalDividerLocation = horizontalDividerLocation;
    }

    public int getFrameWidth() {
        return this.frameWidth;
    }

    public void setFrameWidth(int frameWidth) {
        this.frameWidth = frameWidth;
    }

    public int getFrameHeight() {
        return this.frameHeight;
    }

    public void setFrameHeight(int frameHeight) {
        this.frameHeight = frameHeight;
    }

    public int getFrameX() {
        return this.frameX;
    }

    public void setFrameX(int frameX) {
        this.frameX = frameX;
    }

    public int getFrameY() {
        return this.frameY;
    }

    public void setFrameY(int frameY) {
        this.frameY = frameY;
    }
}
